import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    arr: [
      {
        No: "A栋-1101",
        price: 2000,
        user: "张先生",
        phone: 13588889999,
        water: 1,
        waterprice: 2.5,
        powerstart: 200,
        powerend: 260,
        powerprice: 0.85,
        area: 80,
        areaprice: 3
      },
      {
        No: "A栋-1102",
        price: 1800,
        user: "周先生",
        phone: 13588889999,
        water: 20,
        waterprice: 2.5,
        powerstart: 180,
        powerend: 260,
        powerprice: 0.85,
        area: 60,
        areaprice: 3
      },
      {
        No: "A栋-1104",
        price: 1800,
        user: "王先生",
        phone: 13588889999,
        water: 5,
        waterprice: 2.5,
        powerstart: 220,
        powerend: 260,
        powerprice: 0.85,
        area: 95,
        areaprice: 3
      },
      {
        No: "A栋-1106",
        price: 1500,
        user: "周先生",
        phone: 13388883398,
        water: 11,
        waterprice: 2.5,
        powerstart: 130,
        powerend: 160,
        powerprice: 0.85,
        area: 30,
        areaprice: 3
      },
      {
        No: "A栋-1107",
        price: 1850,
        user: "刘小姐",
        phone: 13783385569,
        water: 15,
        waterprice: 2.5,
        powerstart: 185,
        powerend: 222,
        powerprice: 0.85,
        area: 60,
        areaprice: 3
      }
    ],
  },
  getters: {
    sum(state) {
      let a = state.arr.reduce((pre, cur) => {
        return (
          pre + cur.price +
          cur.water * cur.waterprice +
          (cur.powerend - cur.powerstart) * cur.powerprice +
          cur.area * cur.areaprice
        );
      }, 0);
      return a;
    },

  },
  mutations: {
    add(state, payload) {
      state.arr.push(payload)
    },
  },
  actions: {
  },
  modules: {
  }
})
